package com.mei.offer;

/**
 * 现在要求输入一个整数n，请你输出斐波那契数列的第n项。n<=39
 */
public class Test9_1 {

    public static void main(String[] args) {
        int n = 10;
        for (int i = 0; i < 10; i++) {
            int result = getNum(i);
            System.out.println(result);
        }

    }

    private static int getNum(int n) {
        int result = 0;
        int firstNum = 0;
        int secondNum = 1;
        if (0 == n) {
            return 0;
        } else if (1 == n) {
            return 1;
        } else {
            for (int i = 2; i <= n; i++) {
                result = firstNum + secondNum;
                firstNum = secondNum;
                secondNum = result;
            }
        }

        return result;
    }


}